home *** CD-ROM | disk | FTP | other *** search
- Path: uuneo.neosoft.com!usenet
- From: Wmatthew@lan-aces.com (W. Matthews)
- Newsgroups: comp.lang.c++
- Subject: Re: Default values for constructor arguments
- Date: 11 Mar 1996 14:40:46 GMT
- Organization: LAN-ACES, Inc.
- Message-ID: <4i1e1e$b7i@uuneo.neosoft.com>
- References: <4hjoof$5qk@newnews.iafrica.com>
- NNTP-Posting-Host: 198.65.178.8
- X-Newsreader: WinVN 0.92.5
-
- In article <4hjoof$5qk@newnews.iafrica.com>, Peter Golda <goldap@telkom11.telkom.co.za> says:
- >
- >Hi,
- >
- >I had a constructor for my MWMessageLog class as follows:
- >
- > MWMessageLog(
- > const RWCString& anExecutableCode,
- > const RWCString& aSystemCode,
- > const RWCString& aLogFilePath );
- >
- >where the class RWCString comes from the Rogue Wave development library
- >and is just a simple string class.
- >
- >Now, I wanted to add default values, so I wrote as follows (knowing that
- >RWCString has a constructor that constructs RWCString from char* and it
- >has an assignment operator):
- >
- > MWMessageLog(
- > ...
- > ...
- > const RWCString& aLogFilePath = "~/logs/" );
- >
- >but now the compiler moans that it doesn't like that since the default
- >value must be passed through a constructor.
- >
- >So, I thought I'd create a static member variable in my class of
- >type RWCstring; initialise it to "~/logs/" and then use the variable's
- >name as my default value in the constructor. But that fails too.
- >
- >The C++ ARM has an example of something similar on page 143 (Ch8, Default
- >Arguments) - but it doesn't seem to work...
- >
- >My question thus is:
- >
- >Can I use default values with classes/types that are not inbuilt, but
- >may be constructed of one inbuilt type value. If so, how can I do it
- >without making a big mess of things ?
- >
- >Thanks,
- >Pete.
- >
- >
- Perhaps you could do some type casting (although I agree with you, it should
- not be so hard to do):
- ...
- const RWCString& aLogFilePath = (RWCString)("~/logs/") );
-
- ______________________________________________
- |Wyatt Matthews: Tech Support Department |
- |WMATTHEW@LAN-ACES.COM -Internet- |
- |WMATTHEW.MHS@LAN-ACES -MHS- |
- |LAN-ACES Tech Support (713)890-9786 |
- |LAN-ACES BBS (713)890-9790 |
- |LAN-ACES Fax (713)890-9731 |
- |LAN-ACES Sales (713)890-9787 |
- ______________________________________________
-